package com.jy.api.service.impl;

import com.jy.api.dao.StockInfoDao;
import com.jy.api.domain.StockInfo;
import com.jy.api.service.StockInfoService;
import com.jy.api.signUpReq.StockInfoReq;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by xiaohua on 2019/4/22.
 */
@Service
public class StockInfoServiceImpl implements StockInfoService {
    @Autowired
    private StockInfoDao infoDao;


    @Override
    public void saveInfoOrUpdate(StockInfoReq req) {
        StockInfo info;
        if (0 == req.getId()) {
            info = new StockInfo();
            BeanUtils.copyProperties(req, info);
            info.setEnabled(true);
        } else {
            info = infoDao.findOne(req.getId());
            BeanUtils.copyProperties(req, info);
            info.setEnabled(true);
        }
        infoDao.save(info);
    }

    @Override
    public void deleteInfoById(StockInfoReq req) {
        StockInfo info =infoDao.findOne(req.getId());
        if (info!=null){
            infoDao.delete(info.getId());
        }
    }
}
